//
//  ApplyDaiKuanViewController.m
//  联付商圈
//
//  Created by 于洋 on 2017/7/21.
//  Copyright © 2017年 lianfu. All rights reserved.
//

#import "ApplyDaiKuanViewController.h"
#import "ApplyDaiKuanCollectionViewCell.h"
@interface ApplyDaiKuanViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic ,strong)NSArray *imageViewArray;
@property (nonatomic ,strong)NSArray *imageViewArray1;

@property(nonatomic ,strong)UICollectionView *DaiKuanCollectionView;
@end

@implementation ApplyDaiKuanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self makeUI];

    self.imageViewArray = @[@"小花",@"现金侠",@"拍拍贷",@"发薪贷"];
    self.imageViewArray1 = @[@"一信贷",@"百度",@"还呗",@"希财"];
    self.navigationItem.title = @"申请贷款";
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)makeUI{

    UILabel *yellowLB = [[UILabel alloc]initWithFrame:CGRectMake(0, 64, SCREENW, 20)];
    yellowLB.backgroundColor = [UIColor colorWithRed:1.00 green:0.87 blue:0.57 alpha:1.00];
    yellowLB.text = @"贷款申请不需要任何中介费,谨防电话诈骗!";
    yellowLB.textColor = [UIColor blackColor];
    yellowLB.font = [UIFont systemFontOfSize:13.0];
    yellowLB.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:yellowLB];

    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //设置cellitem大小
    layout.itemSize = CGSizeMake((SCREENW-30)/2, 100);
    //上左下右设置组边距
    layout.sectionInset = UIEdgeInsetsMake(0, 10,0,10);
    //设置cellitem 上下间距
    layout.minimumLineSpacing = 10;
    //设置cellitem左右间距
    layout.minimumInteritemSpacing = 10;
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;

    _DaiKuanCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, yellowLB.maxY, SCREENW, SCREENH) collectionViewLayout:layout];
    _DaiKuanCollectionView.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.00];
    _DaiKuanCollectionView.delegate = self;
    _DaiKuanCollectionView.dataSource = self;
    [_DaiKuanCollectionView registerClass:[ApplyDaiKuanCollectionViewCell class]
               forCellWithReuseIdentifier:@"DaiKuanCell"];
    _DaiKuanCollectionView.contentSize = CGSizeMake(0, SCREENH + 100);
    //设置collectionview组视图
    [_DaiKuanCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];
    //当界面内容不超过界面大小时不会滑动，加上面这句话就能滑动了
    _DaiKuanCollectionView.alwaysBounceVertical = YES;



    [self.view addSubview:_DaiKuanCollectionView];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{


    return 4;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    ApplyDaiKuanCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DaiKuanCell" forIndexPath:indexPath];
    
    if (indexPath.section == 0) {
            cell.ApplyimageView.image = [UIImage imageNamed:[self.imageViewArray objectAtIndex:indexPath.row]];
        
    }else{
        cell.ApplyimageView.image = [UIImage imageNamed:[self.imageViewArray1 objectAtIndex:indexPath.row]];
    }

    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {
        
        if (indexPath.row == 0) {
            
            
        }else if (indexPath.row == 1){
        
        }else if (indexPath.row == 2){
            
        }else{
            
        }
    }
    
    if (indexPath.section == 1) {
        
        if (indexPath.row == 0) {
            
            
        }else if (indexPath.row == 1){
            
        }else if (indexPath.row == 2){
            
        }else{
            
        }
    }
    NSLog(@"%ld%ld",(long)indexPath.row,indexPath.section);
    
}

//创建头视图
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
           viewForSupplementaryElementOfKind:(NSString *)kind
                                 atIndexPath:(NSIndexPath *)indexPath {
    
    
    UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
    
    if (indexPath.section == 0) {
        
        UIView *image = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 10, 20)];
        image.backgroundColor = [UIColor colorWithRed:0.21 green:0.62 blue:0.85 alpha:1.00];
        //image.image = [UIImage imageNamed:@""];
        [headerView addSubview:image];
        
        
        UILabel *lb =  [[UILabel alloc]initWithFrame:CGRectMake(20, 0, headerView.frame.size.width, 40)];
        lb.text = @"大额推荐";
        //lb.textColor = [UIColor greenColor];
        //headerView.backgroundColor = [UIColor redColor];
        [headerView addSubview:lb];

        
    }else{
    
        UIView *image = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 10, 20)];
        image.backgroundColor = [UIColor colorWithRed:0.21 green:0.62 blue:0.85 alpha:1.00];
        //image.image = [UIImage imageNamed:@""];
        [headerView addSubview:image];
        
        UILabel *lb =  [[UILabel alloc]initWithFrame:CGRectMake(20, 0, headerView.frame.size.width, 40)];
        lb.text = @"急速房贷";
        //lb.textColor = [UIColor greenColor];
        //headerView.backgroundColor = [UIColor redColor];
        [headerView addSubview:lb];
    }
    
       return headerView;
}

//设置组视图的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout
referenceSizeForHeaderInSection:(NSInteger)section {
    
    if (section == 0) {
        
        return CGSizeMake(self.view.frame.size.width, 40);
    }
    else if(section ==1){
        
        return CGSizeMake(self.view.frame.size.width, 40);

    }else{
    
        return CGSizeMake(0, 0);

    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
